﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaultBackService.DAL
{
    class RealTimeFaultDataDaily
    {
        /// <summary>
        /// 获取风机每日故障表的最新日期，没有则返回默认值(1970-1-1)
        /// </summary>
        /// <returns></returns>
        internal DateTime GetLastDate()
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                var data = context.RealTimeFaultDataDaily
                    .OrderByDescending(d => d.FaultDataDailyId)
                    .FirstOrDefault();
                if (data==null)
                {
                    return Shared.Global.DefaultTime;
                }
                else
                {
                    return data.Date;
                }
            }
        }

        /// <summary>
        /// 写入数据库，返回写入的记录数目
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        internal int AddList(IList<Models.RealTimeFaultDataDaily> list)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                context.RealTimeFaultDataDaily.AddRange(list);
                return context.SaveChanges();
            }
        }
    }
}
